#ifndef __COMMON_H__
#define __COMMON_H__
#ifdef __cplusplus
extern "C" {
#endif

#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <pthread.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include "serial.h"
#include "myStack.h"
#include "myQueue.h"
#include <system.h>
#include <stddef.h>

/* 正式发布要 注释掉 */
//#define USERDEBUG

#define VERSION	"1.5.6"				// 9.9.9

#define DEFAULT_MQTT_SER			"www.juemingt.com"
#define DEFAULT_MQTT_PORT			11884
#define DEFAULT_MQTT_QOS			0
#define DEFAULT_MQTT_KEEPALIVE		60

#define MQTT_USER_NAME				"jueming20250815"
#define MQTT_PASSWD					"eyJhbGciOi874046$"

//#define CONFIG_TOP_PATH			"/userdata"		//放在 /oem/init.d/S10BasicControl 脚本中切换
#define CONFIG_TOP_PATH				"."

#define WARN_RECORD_PATH			CONFIG_TOP_PATH"/warn_record"
#define	VOICE_FILE_PATH				CONFIG_TOP_PATH"/voice_record"

#define DEV_FILE					CONFIG_TOP_PATH"/gw_info.json"			//主机信息：sn码,组网地址
#define DEV_NODE_FILE				CONFIG_TOP_PATH"/dev_node_info.json"	//终端信息
#define WATER_LEVEL_FILE			CONFIG_TOP_PATH"/water_level.json"		//三级水位报警值

#define FIRMWARE_PATH				CONFIG_TOP_PATH"/firmware"				//固件

#define BROADCAST_TASK_PATH			CONFIG_TOP_PATH"/broadcast_task"		//广播任务
#define BROADCAST_FILE_PATH         CONFIG_TOP_PATH"/broadcast_file"		//广播任务 录制的语音	U盘上传的文件

#define	QT_IMAGE_PATH				CONFIG_TOP_PATH"/res/images"			//QT图片资源路径,跟QT工程对应

#define	TRANSFER_WAY_PICNAME		"transferPic.png"						//QT首页转移路线图片名

//#define SLEEP_MODE_FILE             "Sleep_Mode"							//create from QT

#define SERIAL_TPUNB_IMX6UL			"/dev/ttymxc3"
#define SERIAL_TPUNB_RK3566			"/dev/ttyS1"

//#define RECORD_SELECT_PIN                   0
//#define RECORD_ENABLE_PIN                   1
//#define RECORD_CTRL_PIN                     2

//#define RECORD_DATA_LEN                     1000
//#define LOCALTIME_LEN                       7

#define MSG_TEXT_LEN		8192
typedef struct {
    long mtype;
    char mtext[MSG_TEXT_LEN];
} msgbuf_t;

typedef struct {
    unsigned char year;
    unsigned char month;
    unsigned char day;
    unsigned char hour;
    unsigned char minute;
    unsigned char second;
    unsigned char weekday;
} user_time_t;

// 定义通信方向，发送给QT为上行，发送给底层为下层
#define MSG_CMD_DOWN                        1
#define MSG_CMD_UP                          2
// 定义与QT之间的消息类型,占消息内容的第一个字节
// 发送呼叫请求，内容为启停标志
#define MSG_TYPE_RECORD_REQ                 0x01
#define MSG_TYPE_RTU_REPORT                 0x03
// 设备心跳包，内容为设备地址，unsigned short
#define MSG_TYPE_ENDPOINT_STATUS            0x05
// 预警通知，内容为预警等级，unsigned short
#define MSG_TYPE_WARNLEVEL                  0x07
// 更换应急方案，内容为方案序号
#define MSG_TYPE_WARNLPLAN                  0x09
// 取消安全预警，内容无
#define MSG_TYPE_WARNCANCEL                 0x0B

//用于屏幕超时无操作 切换到屏保页面
#define MSG_TYPE_PAGESWITCH                 0x0D

//用于更新绑定的终端信息
#define MSG_TYPE_UPDATE_DEVNODE_FROMFILE    0x0F

//获取在线状态
#define MSG_TYPE_GET_ONLINE  				0x11

//触发报警
#define MSG_TYPE_TRIGGER_ALARM 				0x13

//水位跟新
#define MSG_TYPE_WATER_LEVEL 				0x15

//停止语音播报
#define MSG_TYPE_STOP_BROADCAST				0x17

//三级报警水位设置
#define MSG_TYPE_WARN_WATER 				0x19

//更新转移路线
#define MSG_TYPE_TRANSFERWAY_SETTING		0x1B

//点播
#define MSG_TYPE_ON_DEMAND					0x1D

//报警器所有状态
#define MSG_TYPE_DEV_STATUS                 0x1F

//呼叫器所有状态
#define MSG_TYPE_GW_STATUS                 	0x21

//播放默认音频
#define MSG_TYPE_PLAY_DEF_WAV              	0x23

//录制音频
#define MSG_TYPE_RECORD_WAV	            	0x25

//播放录制音频
#define MSG_TYPE_PLAY_RECORD_WAV	       	0x27

//发送广播任务
#define MSG_TYPE_SEND_BROADCAST_TASK       	0x29

//更新QT界面广播任务应答状态
#define MSG_TYPE_BROADCAST_TASK_ANSWER     	0x2B

//雨量更新
#define MSG_TYPE_RAIN_LEVEL 				0x2D

#define WARN_LEVEL_EMERG                    0x01	//立即转移
#define WARN_LEVEL_WARN                     0x02	//准备转移
#define WARN_LEVEL_INFO                     0x03	//注意安全
#define WARN_LEVEL_CANCEL                   0x04	//取消警报

void qt_msg_send(void *msgp, int msgsz);

#define DEBUG(format,...)	log_printf(""format"\n",  ##__VA_ARGS__ )

#define DEBUG_ERR(format,...)	log_printf(""format"\n",  ##__VA_ARGS__ )

#ifdef __cplusplus
}
#endif
#endif

